package edu.ynu.se.xiecheng.achitectureclass.service;

import edu.ynu.se.xiecheng.achitectureclass.common.service.LogicService;
import edu.ynu.se.xiecheng.achitectureclass.dao.UserDao;
import edu.ynu.se.xiecheng.achitectureclass.entity.Business;
import edu.ynu.se.xiecheng.achitectureclass.entity.Customer;
import edu.ynu.se.xiecheng.achitectureclass.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;



@Service
public class UserService extends LogicService<UserDao,User,Long> {

    public UserService(@Qualifier("userDao") @Autowired UserDao dao) {
        super(dao);
    }

    /**
     * 用户登录方法
     *
     * @param username 用户名
     * @param password 密码
     * @return 返回登录用户的类型（"merchant" 或 "customer"），如果登录失败返回 null
     */
    public String login(String username, String password) {
        User user = dao.findByUsername(username); // 假设通过用户名查询用户对象的方法为 findByUsername

        if (user != null && user.getPassword().equals(password)) {
            if (user instanceof Business) {
                return "商家用户登录成功"; // 商家用户登录成功
            } else if (user instanceof Customer) {
                return "顾客用户登录成功"; // 顾客用户登录成功
            }
        }
        return null; // 登录失败
    }

}
